package dst1.model;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import dst1.listener.DefaultEntityListener;

@Entity
@Table(name="EXECUTION")
public class Execution implements Serializable{
	@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="ID") 
	private Long id;
	
	@Column(name="START") 
	//@Temporal(TemporalType.TIMESTAMP)
	private Date start;
	
	@Column(name="END") 
	//@Temporal(TemporalType.TIMESTAMP)
	private Date end;
	
	@Column(name="STATUS") 
	private JobStatus status;
	
	@OneToOne(cascade=CascadeType.ALL)
	private Job job;
	
	@ManyToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY)
	@JoinTable(name = "EXECUTION_COMPUTER", //automatisches Mitspeichern funktioniert sonst nicht
	   joinColumns={@JoinColumn(name="EXECUTION_ID", referencedColumnName="ID", nullable=false)},
	   inverseJoinColumns={@JoinColumn(name="COMPUTER_ID", referencedColumnName="ID", nullable=false)})
	private List<Computer> computers;
	
	public Execution(){
		
	}

	public Execution(Date start, Date end, JobStatus status, Job job,
			List<Computer> computers) {
		super();
		this.start = start;
		this.end = end;
		this.status = status;
		this.job = job;
		this.computers = computers;
	}

	public Long getId() {
		return id;
	}
	public Date getStart() {
		return start;
	}

	public void setStart(Date start) {
		this.start = start;
	}

	public Date getEnd() {
		return end;
	}

	public void setEnd(Date end) {
		this.end = end;
	}

	public JobStatus getStatus() {
		return status;
	}

	public void setStatus(JobStatus status) {
		this.status = status;
	}

	public Job getJob() {
		return job;
	}

	public void setJob(Job job) {
		this.job = job;
	}

	public List<Computer> getComputers() {
		return computers;
	}

	public void setComputers(List<Computer> computers) {
		this.computers = computers;
	}
	

}
